package com.tan.controller;

import com.tan.domain.response.Result;
import com.tan.domain.response.StatusCode;
import com.tan.mapper.CommentMapper;
import com.tan.service.BlogService;
import com.tan.service.CommentService;
import com.tan.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @description:
 * @author: longshifu
 * @time: 2023/5/31 21:33
 */
@RestController
public class CommentController {

    @Autowired
    CommentService commentService;
    @Autowired
    CommentMapper commentMapper;


    @Autowired
    UserService userService;
    @Autowired
    BlogService blogService;

    @GetMapping("/comments/{blogId}")
    public Result comments(@PathVariable Long blogId) {
        System.out.println(blogId);
        return new Result(true, StatusCode.OK, "获取博客评论成功", commentService.getCommentsByBlogId(blogId));
    }

    /**
     * 新增评论
     *
     * @param para
     * @return
     */
    @PostMapping("/comments")
    public Result post(@RequestBody Map<String, Object> para) {
        System.out.println(para);
        return new Result(true, StatusCode.OK, "评论发表成功", commentService.addComment(para));
    }


    @GetMapping("/comments/{id}/delete")
    public Result deleteComment(@PathVariable Long id) {
        commentMapper.deleteById(id);
        return new Result(true, StatusCode.OK, "删除评论成功", null);
    }
}
